package model;

/**
 * Course.java
 * Purpose: this class represents a course that a student might take
 * 
 * @author Hans Brems
 * @version 1.0 03/11/2011
 */

import model.enums.CourseMinutes;
import model.enums.Credits;

public class Course implements Cloneable, Comparable<Course>,Business {
	
	private int code;
	private Credits credits;
	private CourseMinutes courseMinutes;
	private String name;
	
	public Course(){}

	/** Constructs a course object */
	public Course(int code, String name, int courseMinutes, int credits) {
		this.code = code;
		this.name = name;
		this.setCredits(credits);
		this.setCourseMinutes(courseMinutes);
	}

	/** Returns the course code **/
	public int getCode() {
		return code;
	}
	
	/** Sets the course code **/
	public void setCode(int code) {
		this.code = code;
	}
	
	/** Returns the course name **/
	public String getName() {
		return name;
	}
	
	/** Sets the course name **/
	public void setName(String name) {
		this.name = name;
	}

	/** Returns the amount of credits one earns from taking this course **/
	public int getCredits() {
		return this.credits.getValue();
	}
	
	/** Sets the amount of credits one earns from taking this course **/
	public void setCredits (int credits) {
		switch (credits) {
			case 3:
				this.credits = Credits.MIN;
				break;
			case 6:
				this.credits = Credits.MAX;
				break;
			default:
				this.credits = Credits.ILLEGAL;
				break;
		}
	}

	/** Returns the total amount of minutes per week that this course is being taught **/
	public int getCourseMinutes() {
		return this.courseMinutes.getValue();
	}
	
	/** Sets the total amount of minutes per week that this course is being taught **/
	public void setCourseMinutes (int courseTime) {
		switch (courseTime) {
			case 120:
				this.courseMinutes = CourseMinutes.MIN;
				break;
			case 240:
				this.courseMinutes = CourseMinutes.MAX;
				break;
			default:
				this.courseMinutes = CourseMinutes.ILLEGAL;
				break;
		}
	}
	
	
	/** Checks for equality with another object */
	@Override
	public boolean equals(Object object) {
		
		Course otherCourse;
		
		// Check for same reference
		if (this == object) {
			return true;
		}
		
		// Check if object type is equal
		if (object == null || object.getClass() != this.getClass()) {
			return false;
		}
		
		// Cast object to correct class
		otherCourse = (Course)object;
			
		// Check if object properties are equal
		return otherCourse.getCode() == this.code;
	}
	
	/** Returns an integer representation of the object **/
	@Override
	public int hashCode() {
        return this.code;
	}
	
	/** Returns a string representation of the object **/
	@Override
	public String toString() {
		//return String.format("%s (credits: %d) (minutes: %d)", this.name, this.credits.getValue(), this.courseMinutes.getValue());
		return name;
	}
	
	/** Clones the object **/
	@Override
	public Object clone() throws CloneNotSupportedException {
		
		// Copy parent
		Course clone = (Course)super.clone();
		
		// Set properties
		clone.code = this.code;
		clone.name = this.name;
		clone.credits = this.credits;
		clone.courseMinutes = this.courseMinutes;
		// Return result
		return clone;
	}

	/** Compares the object to another object **/
	@Override
	public int compareTo(Course course) {
		return 0;
	}

}